package com.siao.utils
{
	import com.siao.applications.ApplicationManager;
	
	import flash.display.StageDisplayState;
	import flash.external.ExternalInterface;
	
	/**
	 * 调用JS方法
	 * @param method
	 * @param args
	 * @return
	 */
	public function call(method:String, ... args):Object
	{
		if (ExternalInterface.available)
		{
			var f:Function = ExternalInterface.call;
			
			try
			{
				if (ApplicationManager.instance.stage.displayState != StageDisplayState.NORMAL)
				{
					ApplicationManager.instance.stage.displayState = StageDisplayState.NORMAL;
				}
				
				var a:Array = new Array();
				a.push(method);
				a.push.apply(a, args);
				
				return f.apply(method, a);
			}
			catch (err:Error)
			{
			}
		}
		
		return null;
	}

}
